{% extends base.html %}

{% block head %}
<style type="text/css">
.key {
    width: 30%;
}

select {
    width: 150px;
}

{% if not _is_admin %}
    .admin-visible {
        display: none;
    }
{% end %}

</style>
{% end %}

{% block body %}

<!-- TODO d3.js 展示内存和CPU日志 -->
{% import web %}

<div class="col-md-12 card">
    <h3 class="card-title">{{T("Menu_Settings")}}</h3>

    <table class="table">
        <tr class="">
            <td class="key">{{T("当前用户")}}</td>
            <td>
                {{_user_name}}
            </td>
        </tr>

        <tr class="user-visible">
            <td class="key">关于系统</td>
            <td>
                <a href="/code/wiki/README.md">查看</a>
            </td>
        </tr>

        <tr class="admin-visible">
            <td class="key">后台管理</td>
            <td><a href="/system/index">进入</a></td>
        </tr>

        <tr class="admin-visible">
            <td class="key">文件管理</td>
            <td><a href="/fs_list">进入</a></td>
        </tr>   

        <tr class="admin-visible">
            <td class="key">系统启动时间</td>
            <td>{{start_time}}</td>
        </tr>
        <tr class="admin-visible">
            <td class="key">系统内存占用</td>
            <td>{{sys_mem_used}} / {{sys_mem_total}}</td>
        </tr>

        <tr class="user-visible hide">
            <td class="key">数据管理</td>
            <td>
                <a href="/note/stat">数据统计</a> |
                <a href="/fs_upload">上传管理</a>
            </td>
        </tr>

        <tr class="admin-visible hide">
            <td class="key">任务管理</td>
            <td>
                <a href="/system/crontab">定时任务</a> |
                <a href="/system/event">系统事件</a>
            </td>
        </tr>

        <tr class="admin-visible hide">
            <td class="key">数据管理</td>
            <td>
                <a href="/system/user/list">用户管理</a> |
                <a href="/tools/sql">{{T("sqlite管理")}}</a> |
                <a href="/system/db_scan">leveldb管理</a> |
                <a href="/system/db_migrate">数据迁移</a> |
                <a href="/tools/shell">Shell</a>
            </td>
        </tr>

        <tr class="admin-visible hide">
            <td class="key">日志监控</td>
            <td>
                <a href="/system/log">系统日志</a> | 
                <a href="/system/clipboard-monitor">剪切板监控</a>
            </td>
        </tr>

        <tr class="admin-visible hide">
            <td class="key">目录管理</td>
            <td>
                <a href="/fs_link/home">Home</a> |
                <a href="/fs_list">Data</a>
            </td>
        </tr>

        <!-- UI设置 -->
        <tr class="user-visible">
            <td class="key">主题</td>
            <td>
                <select name="THEME" data-type="str" value="{{_user_config.THEME}}">
                    <option value="standard">默认</option>
                    <option value="card">卡片</option>
                    <option value="left">侧边栏</option>
                </select>
            </td>
        </tr>

        <tr class="user-visible hide">
            <td class="key">待办模式</td>
            <td>
                <input type="radio" data-type="bool" name="TODO_MODE" default-value="{{_user_config.TODO_MODE}}" value="True">开启
                <input type="radio" data-type="bool" name="TODO_MODE" default-value="{{_user_config.TODO_MODE}}" value="False">关闭
            </td>
        </tr>

        <tr class="user-visible">
            <td class="key">首页</td>
            <td>
                <select name="HOME_PATH" data-type="str" value="{{HOME_PATH}}">
                    <option value="/note/group">项目列表</option>
                    <option value="/note/index">分类和工具</option>
                    <option value="/note/timeline">项目时光轴</option>
                </select>
            </td>
        </tr>

        <tr class="admin-visible hide">
            <td class="key">选项风格</td>
            <td>
                <input type="radio" name="OPTION_STYLE" default-value="{{xconfig.OPTION_STYLE}}" value="aside">侧边
                <input type="radio" name="OPTION_STYLE" default-value="{{xconfig.OPTION_STYLE}}" value="top">顶部
            </td>
        </tr>

        <tr class="admin-visible hide">
            <td class="key">宽度</td>
            <td>
                <input type="radio" name="PAGE_WIDTH" default-value="{{xconfig.PAGE_WIDTH}}" value="1150">1150
                <input type="radio" name="PAGE_WIDTH" default-value="{{xconfig.PAGE_WIDTH}}" value="900">900
            </td>
        </tr>

        <tr class="admin-visible">
            <td class="key">文件视图</td>
            <td>
                <select name="FS_VIEW_MODE" data-type="str" value="{{xconfig.FS_VIEW_MODE}}">
                    <option value="list">列表</option>
                    <option value="grid">网格</option>
                    <option value="sidebar">侧栏</option>
                </select>
            </td>
        </tr>

        <tr class="admin-visible">
            <td class="key">页面打开</td>
            <td>
                <select name="PAGE_OPEN" data-type="str" value="{{xconfig.PAGE_OPEN}}">
                    <option value="self">当前页面</option>
                    <option value="dialog">弹层</option>
                </select>
            </td>
        </tr>

        <tr class="user-visible">
            <td class="key">{{T('语言')}}</td>
            <td>
                <select name="LANG" data-type="str" value="{{_user_config.LANG}}">
                    <option value="zh">中文</option>
                    <option value="en">English</option>
                </select>
            </td>
        </tr>
        <!--
        <tr class="admin-visible">
            <td class="key">{{T("Recent Search")}}</td>
            <td>
                <select name="RECENT_SEARCH_LIMIT" value="{{xconfig.RECENT_SEARCH_LIMIT}}">
                    <option value="10">10</option>
                    <option value="15">15</option>
                    <option value="20">20</option>
                    <option value="30">30</option>
                </select>
            </td>
        </tr>
        <tr class="admin-visible">
            <td class="key">{{T("Recent Modified")}}</td>
            <td>
                <input type="radio" name="RECENT_SIZE" default-value="{{xconfig.RECENT_SIZE}}" value="6">6
                <input type="radio" name="RECENT_SIZE" default-value="{{xconfig.RECENT_SIZE}}" value="9">9
                <input type="radio" name="RECENT_SIZE" default-value="{{xconfig.RECENT_SIZE}}" value="12">12
            </td>
        </tr>
        -->
        <tr class="admin-visible">
            <td class="key">{{T("Page Size")}}</td>
            <td>
                <select name="PAGE_SIZE" data-type="int" value="{{xconfig.PAGE_SIZE}}">
                    <option value="20">20</option>
                    <option value="30">30</option>
                    <option value="50">50</option>
                    <option value="100">100</option>
                    <option value="200">200</option>
                </select>
            </td>
        </tr>
        <tr class="admin-visible">
            <td class="key">系统文件</td>
            <td>
                <input type="radio" name="FS_HIDE_FILES" default-value="{{xconfig.FS_HIDE_FILES}}" value="True">隐藏
                <input type="radio" name="FS_HIDE_FILES" default-value="{{xconfig.FS_HIDE_FILES}}" value="False">显示
            </td>
        </tr>

        <tr class="admin-visible">
            <td class="key">功能调试</td>
            <td>
                <input type="radio" name="DEBUG" default-value="{{xconfig.DEBUG}}" value="True">开启
                <input type="radio" name="DEBUG" default-value="{{xconfig.DEBUG}}" value="False">关闭
            </td>
        </tr>
        <tr class="admin-visible">
            <td class="key">页面调试</td>
            <td>
                <input type="radio" name="DEBUG_HTML_BOX" default-value="{{xconfig.DEBUG_HTML_BOX}}" value="True">开启
                <input type="radio" name="DEBUG_HTML_BOX" default-value="{{xconfig.DEBUG_HTML_BOX}}" value="False">关闭
            </td>
        </tr>
        <tr class="admin-visible">
            <td class="key">实验室功能</td>
            <td>
                <input type="radio" name="DEV_MODE" default-value="{{xconfig.DEV_MODE}}" value="True">开启
                <input type="radio" name="DEV_MODE" default-value="{{xconfig.DEV_MODE}}" value="False">关闭
            </td>
        </tr>
        <tr class="admin-visible">
            <td class="key">记录位置</td>
            <td>
                <input type="radio" name="RECORD_LOCATION" default-value="{{xconfig.RECORD_LOCATION}}" value="True">开启
                <input type="radio" name="RECORD_LOCATION" default-value="{{xconfig.RECORD_LOCATION}}" value="False">关闭
            </td>
        </tr>

        <tr class="admin-visible">
            <td class="key">回收站清理</td>
            <td>
                <select name="TRASH_EXPIRE" data-type="int" value="{{xconfig.TRASH_EXPIRE}}">
                    <option value="2592000">30天</option>
                    <option value="7776000">90天</option>
                    <option value="15552000">180天</option>
                    <option value="31104000">360天</option>
                </select>
            </td>
        </tr>

        <tr class="admin-visible">
            <td class="key">高级配置</td>
            <td>
                <a href="{{init_script_url}}">启动脚本</a> |
                <a href="/code/edit?type=script&path=user.css">CSS配置</a>
            </td>
        </tr>
        
        {% if _is_admin %}
            <!-- 系统信息，有敏感信息 -->
            <tr class="admin-visible">
                <td class="key">处理器</td>
                <td>{{processor}}</td>
            </tr>
            <tr class="admin-visible">
                <td class="key">OS版本</td>
                <td>{{sys_version}}</td>
            </tr>
            <tr class="admin-visible">
                <td class="key">Python版本</td>
                <td>{{python_version}}</td>
            </tr>
            {% for item in item_list %}
                <tr>
                    <td class="key">{{item.key}}</td>
                    <td>{{item.value}}</td>
                </tr>
            {% end %}
        {% end %}
    </table>
</div>

<script type="text/javascript">
    function updateSetting(key, value, type) {
        $.post("/system/config", 
            {key: key, value: value, type: type}, 
            function (data) {
                window.location.reload();
        }).fail(function (resp) {
            console.log(resp);
            alert("设置失败");
        });
    }

    $("[type=radio]").on("change", function (e) {
        var val = $(e.target).val();
        var key = $(e.target).attr("name");
        var type = $(this).attr("data-type");
        // alert(val);
        updateSetting(key, val, type);
    });

    $("select").change(function (e) {
        var key = $(this).attr("name");
        var val = $(this).val();
        var type = $(this).attr("data-type");
        updateSetting(key, val, type);
    });
</script>

{% end %}